package com.cskaoyan._19collection._01ds;

import org.junit.Test;

import java.util.Arrays;

/**
 * @author Macro_Ray
 * @since 2024/3/28 14:52
 */
// 数组的相关操作
public class ArrayDemo {
    // 数组添加元素
    @Test
    public void test1(){
        String[] teaList = new String[]{"茶百道","书亦烧仙草","蜜雪冰城","茶颜悦色","喜茶","霸王茶姬"};

        // 因为数组的长度是固定的，所以不能直接添加元素，只能新建一个数组
        String[] newTeaList = new String[teaList.length+1];

        System.out.println("原数组：" + Arrays.toString(teaList));
        for (int i = 0; i < teaList.length; i++) {
            newTeaList[i] = teaList[i];
        }
        System.out.println("新数组：" + Arrays.toString(newTeaList));

        int index = 2;
        for (int j = teaList.length-1; j >=index ; j--) {
            newTeaList[j+1] = teaList[j];
        }
        newTeaList[index] = "七分甜";
        System.out.println("添加之后：" + Arrays.toString(newTeaList));



    }
}
